#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
import functools

__author__ = 'Administrator'

def singleton(obj):
    instances ={}
    @functools.wraps(obj)
    def _wrapper(*args, **kw):
        if obj not in instances:
            instances[obj] = obj(*args, **kw)
        return instances[obj]
    return _wrapper

@singleton
class Log():

    def __init__(self, name='root'):
        self._logger = logging.getLogger(name)
        self._sh = logging.StreamHandler()
        self._fm = logging.Formatter('[%(asctime)s %(module)s.%(funcName)s(%(lineno)d) %(levelname)s]: %(message)s')
        self._sh.setFormatter(self._fm)
        self._logger.addHandler(self._sh)
        self._logger.setLevel(logging.INFO)

    @property
    def get_logger(self):
        return self._logger

L = Log(__name__).get_logger

if __name__ == '__main__':
    L.info('this is info')
    L.debug('this is debug')
    L.warning('this is warn')
    L.error('this is error')
